package com.hx.utils;

import com.hx.entity.MobileCard;
import com.hx.entity.ServicePackage;

import java.util.Scanner;

public class UserInterfase {
    ServicePackage service = new ServicePackage();
    MobileCard mobileCard = new MobileCard();
    CardUtils cardUtils = new CardUtils();
    Scanner scanner = new Scanner( System.in );
    boolean t = true;
    boolean tt = true;

    public void start() {
        cardUtils.intitScene();
        do {
            System.out.println( "****************欢迎使用嗖嗖移动业务大厅*****************" );
            System.out.println( "1.用户登录     2.用户注册     3.使用嗖嗖     4.话费充值     5.资费说明     6.退出系统" );
            System.out.println( "请选择：" );

            int s = 1;try {
                s=scanner.nextInt();}
            catch (Exception e){
                System.out.println("输入有误，重新输入");}
            switch (s) {
                case 1:
                    cardMenu();
                    continue;
                case 2:
                    registCard();
                    continue;
                case 3:
                    System.out.println( "使用嗖嗖功能" );
                    System.out.println( "请输入你的号码" );
                    String number = scanner.next();
                    cardUtils.userSoso( number );
                    continue;
                case 4:
                    cardUtils.moneyRecharge();
                    continue;
                case 5:
                    cardUtils.showDescription();

                    continue;
                case 6:
                    System.out.println( "谢谢使用" );
                    break;
                default:
                    System.out.println( "输入错误，请重新输入！" );
            }
        } while (t);
    }

    public void cardMenu() {
        System.out.println( "请输入您的手机号：" );
        String number = scanner.next();
        System.out.println( "请输入您的密码" );
        String pwd = scanner.next();

        if (cardUtils.isExistCard( number, pwd )) {
            System.out.println( "登录成功" );
        } else {
            return;
        }
        do {
            System.out.println( "******嗖嗖移动用户菜单" );
            System.out.println( "1.本月账单查询" );
            System.out.println( "2.套餐余量查询" );
            System.out.println( "3.打印消费详单" );
            System.out.println( "4.套餐变更" );
            System.out.println( "5.办理退网" );
            System.out.print( "请选择(输入1~5选择功能,其他键返回上一级)：" );
            int s2 = scanner.nextInt();

            switch (s2) {
                case 1:
                    cardUtils.showAmountDetail( number );  //调用本月账单查询
                    continue;
                case 2:
                    cardUtils.showRemainDetail( number );  //调用套餐余量查询
                    continue;
                case 3:
                    cardUtils.printConsumIofo( number ); //调用打印消费详单
                    continue;
                case 4:
                    cardUtils.changingPack(number );//套餐变更
                    continue;
                case 5:
                    cardUtils.delCard( number );        //办理退网
                default:
                    tt = false;
            }
        } while (tt);

    }
    //注册卡号
    private void  registCard() {
        System.out.println( "************可选择的卡号************" );
        //通过超级循环遍历输出卡号
        String[] cardNumbers = cardUtils.getNewNumber( 9 );
        for (int i = 0; i < cardNumbers.length; i++) {
            System.out.print( (i + 1) + ":" + cardNumbers[i] + "\t" );
        }

        System.out.println( "\n请选择卡号(输入1~9的序号)：" );
        int key = scanner.nextInt();
        if (key >= 1 && key <= 9) {
            mobileCard.setCardnumber( cardNumbers[key - 1] );
            System.out.println( "1.话唠套餐  2.网虫套餐  3.超人套餐 ， 请选择套餐（输入序号）:" );
        } else {
            System.out.print( "输入错误！请输入（1~9）的整数:" );
        }
        boolean bol = true;
        int packageNum = scanner.nextInt();
        while (bol) {
            if (packageNum <= 3 && packageNum >= 1) {
                service = cardUtils.createPackage( packageNum );
                mobileCard.setSerPackage( service );
                bol = false;
            } else {
                System.out.println( "输入错误，请重新选择：" );
                packageNum = scanner.nextInt();
            }
        }
        System.out.println( "请输入姓名：" );
        String userName = scanner.next();
        System.out.println( "请输入密码：" );
        String passWord = scanner.next();
        System.out.println( "请输入预存话费：" );
        double money = scanner.nextInt();
        while (money < service.getPrice()) {
            System.out.println( "您预存话费金额不足以支付本月固定套餐资费，请重新充值：" );
            money = scanner.nextInt();
        }
        //当前输入的余额减去月租
        mobileCard.setMonery( money - service.getPrice() );
        //注册新用户添加到集合
        MobileCard card = new MobileCard( mobileCard.getCardnumber(), userName, passWord, mobileCard.getMonery(), mobileCard.getSerPackage() );
        cardUtils.addCard( card );
        System.out.println("注册完成！");
        //cardUtils.saveData();
        card.showMeg();
    }
}
